USE JICCDB
GO
CREATE PROC proc_UpdateUser
@LoginID	VARCHAR(16),
@Password	VARCHAR(20),
@NickName	VARCHAR(16),
@Name		VARCHAR(5),
@Phone		VARCHAR(15),
@Sex		CHAR(2),
@Birthday	VARCHAR(10),
@Email		VARCHAR(50),
@Address	VARCHAR(100),
@DptName	VARCHAR(10),
@UserPhoto	VARCHAR(50),
@Memo		VARCHAR(150)
AS

DECLARE @count int
SELECT @count = COUNT(*) FROM tab_User WHERE LoginID = @LoginID
IF(@count <> 1)
BEGIN
RETURN(2)
END
ELSE
BEGIN

DECLARE @dptID INT
SELECT @dptID = DptID FROM tab_Department WHERE DptName = @DptName

IF(LEN(@Password) = 0)
BEGIN
UPDATE tab_User SET NickName = @NickName, Name = @Name, 
Phone = @Phone, Sex = @Sex, Birthday = @Birthday, Email = @Email, Address = @Address, 
DptID = @DptID, UserPhoto = @UserPhoto, Memo = @Memo
WHERE LoginID = @LoginID
RETURN(0)
END
ELSE
BEGIN
UPDATE tab_User SET Password = @Password, NickName = @NickName, Name = @Name, 
Phone = @Phone, Sex = @Sex, Birthday = @Birthday, Email = @Email, Address = @Address, 
DptID = @DptID, UserPhoto = @UserPhoto, Memo = @Memo
WHERE LoginID = @LoginID
RETURN(0)
END

END
RETURN(1)
GO